package com.anolesoft.twelvePlan.mapper;

import cn.hutool.core.util.StrUtil;
import com.anolesoft.twelvePlan.dto.BasWorkhourCountDTO;
import com.anolesoft.twelvePlan.entity.BasWorkhourCountDO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

/**
 * @author zyq
 * @date 2022/6/21
 */
@Mapper
public interface BasWorkhourCountMapper {
    @SelectProvider(type = createSQL.class, method = "querySQL")
    List<BasWorkhourCountDTO> queryWorkHour(@Param("basWorkhourCountDO") BasWorkhourCountDO basWorkhourCountDO, Page<BasWorkhourCountDTO> page);
    public static class createSQL {
        public static String querySQL(@Param("basWorkhourCountDO") BasWorkhourCountDO basWorkhourCountDO, Page<BasWorkhourCountDTO> page){
            return new SQL(){
                {
                    StringBuffer sql = new StringBuffer();
                    sql.append(" a.v_date, a.gongzhong, a.wcgs, a.wwgs, round(a.wcgs/a.wwgs,2)*100 || '%' as wanchenglv from bas_workhour_count a");
                    sql.append(" where a.factory_id = #{basWorkhourCountDO.factoryId}");
                    if (!StrUtil.isEmptyOrUndefined(basWorkhourCountDO.getVDate())) {
                        sql.append(" and a.v_date = #{basWorkhourCountDO.vDate}");
                    }
                    if (!StrUtil.isEmptyOrUndefined(basWorkhourCountDO.getGongzhong())) {
                        sql.append(" and a.gongzhong = trim(#{basWorkhourCountDO.gongzhong})");
                    }
                    SELECT(sql.toString());
                    System.out.println("queryWorkHourSQL:" + sql.toString());
                }
            }.toString();
        }
    }

}
